package com.example.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.pojo.measuringToolChecklistPojo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface measuringToolChecklistMapp {
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_measuring_tool_checklist where ${fieldName}>=#{minVal} and ${fieldName}<#{maxVal} and sys_deleted=0")
    List<measuringToolChecklistPojo> queryOneField(String fieldName, LocalDateTime minVal, LocalDateTime maxVal);

    @DS("newMscLowCodeFormal")
    @Update("update ddm_measuring_tool_checklist set " +
            "update_time = #{update_time}, " +
            "creator = #{creator}, " +
            "process_status = #{process_status}, " +
            "sys_update_user = #{sys_update_user}, " +
            "sys_audit_user = #{sys_audit_user}, " +
            "sys_audit_time = #{sys_audit_time}, " +
            "sys_deleted = #{sys_deleted}, " +
            "number = #{number}, " +
            "name = #{name}, " +
            "name_english = #{name_english}, " +
            "name_russian = #{name_russian}, " +
            "inspection_frequency = #{inspection_frequency}, " +
            "is_qualified = #{is_qualified}, " +
            "abnormal_description = #{abnormal_description} " +
            "where id = #{id}")
    void editOneById(measuringToolChecklistPojo measuringToolChecklistPojo);
    //对一个字段，从老值更改为新值
    @DS("newMscLowCodeFormal")
    @Update("update ddm_measuring_tool_checklist set ${fieldName}=#{newData} where ${fieldName}=#{old}")
    void editByField(String fieldName, String old, String newData);
    //查询点检表中给定时间范围内的点检数据
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_measuring_tool_checklist where create_time>=#{startTime} and create_time<=#{endTime} and number=#{numberUse}")
    List<measuringToolChecklistPojo> queryTimeAndNumber(LocalDateTime startTime, LocalDateTime endTime, String numberUse);

    //插入一条点检数据
    @DS("newMscLowCodeFormal")
    @Insert("insert into ddm_measuring_tool_checklist(" +
            "id, create_time, update_time, " +
            "creator, process_status, sys_update_user, " +
            "sys_audit_user, sys_audit_time, sys_deleted, " +
            "number, name, name_english, " +
            "name_russian, is_qualified, abnormal_description, " +
            "basicInformationId, inspection_frequency)" +
            "values (" +
            "#{id}, #{create_time}, #{update_time}, " +
            "#{creator}, #{process_status}, #{sys_update_user}, " +
            "#{sys_audit_user}, #{sys_audit_time}, #{sys_deleted}, " +
            "#{number}, #{name}, #{name_english}, " +
            "#{name_russian}, #{is_qualified}, #{abnormal_description}, " +
            "#{basicInformationId}, #{inspection_frequency})")
    void insertOne(measuringToolChecklistPojo pojo);

    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_measuring_tool_checklist where number=#{number} and create_time=#{date}")
    List<measuringToolChecklistPojo> queryTimeNumber(String number, LocalDateTime date);

    //把当日点检的所有记录调出来
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_measuring_tool_checklist where ${fieldName}>=#{startTime} and ${fieldName}<=#{endTime} and sys_deleted=0")
    List<measuringToolChecklistPojo> queryBetweenTwoTime(String fieldName, LocalDateTime startTime, LocalDateTime endTime);
}